//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ksyun.media.shortvideo.com.ksyun.media.shortvideo.utils;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.ksy.statlibrary.util.ContextUtil;
import com.ksyun.media.streamer.util.https.HttpResponseListener;
import com.ksyun.media.streamer.util.https.KsyHttpConnection;
import com.ksyun.media.streamer.util.https.KsyHttpResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

public class AuthInfoManager {
    private static final String a = "AuthInfoManager";
    private static String b = "https://ksvs.cn-beijing-6.api.ksyun.com";
    public static int AUTH_SUCCESS = 1;
    public static int AUTH_FAILED = -1;
    private static int c = 0;
    private AuthInfoManager.a d;
    private String e;
    private String f;
    private Context g = ContextUtil.getContext();
    private String h;
    private KsyHttpConnection i;
    private HttpResponseListener j;
    private List<AuthInfoManager.CheckAuthResultListener> k = new LinkedList();
    private static AuthInfoManager l;

    public static AuthInfoManager getInstance() {
        if(l == null) {
            Class var0 = AuthInfoManager.class;
            synchronized(AuthInfoManager.class) {
                if(l == null) {
                    l = new AuthInfoManager();
                }
            }
        }

        return l;
    }

    private AuthInfoManager() {
    }

    public void release() {
        this.removeAllAuthListeners();
        this.j = null;
        this.g = null;
    }

    public void setAuthInfo(String var1, String var2) {
        this.e = var1;
        this.f = var2;
    }

    public void setAuthInfo(String var1) {
        this.h = var1;
    }

    public synchronized void addAuthResultListener(AuthInfoManager.CheckAuthResultListener var1) {
        this.k.add(var1);
    }

    public synchronized void removeAuthResultListener(AuthInfoManager.CheckAuthResultListener var1) {
        if(this.k.contains(var1)) {
            this.k.remove(var1);
        }

    }

    public synchronized void removeAllAuthListeners() {
        this.k.clear();
    }

    private synchronized void a() {
        if(this.k != null) {
            for(int var1 = 0; var1 < this.k.size(); ++var1) {
                ((AuthInfoManager.CheckAuthResultListener)this.k.get(var1)).onAuthResult(this.getAuthState()?AUTH_SUCCESS:AUTH_FAILED);
            }
        }

    }

    public void checkAuth() {
//
    }

    public AuthInfoManager.a getAuthInfo() {
        return this.d;
    }

    public boolean getAuthState() {
        return this.d != null && this.d.a == AUTH_SUCCESS;
    }

    public String getAuthExpiredData() {
        return this.d != null?this.d.c:"";
    }

    public class a {
        protected int a;
        private String c;

        public a(JSONObject var2) {
            this.a = AuthInfoManager.AUTH_FAILED;
            this.c = "";

            try {
                JSONObject var3 = var2.getJSONObject("Data");
                int var4 = var3.getInt("RetCode");
                if(var4 == 0) {
                    this.a = AuthInfoManager.AUTH_SUCCESS;
                } else {
                    this.a = AuthInfoManager.AUTH_FAILED;
                }
            } catch (JSONException var5) {
                var5.printStackTrace();
            }

        }

        public a(int var2) {
            this.a = AuthInfoManager.AUTH_FAILED;
            this.c = "";
            this.a = var2;
        }

        public a(int var2, String var3) {
            this.a = AuthInfoManager.AUTH_FAILED;
            this.c = "";
            this.a = var2;
            this.c = var3;
        }
    }

    public interface CheckAuthResultListener {
        void onAuthResult(int var1);
    }

    public class CheckAuthResponse implements HttpResponseListener {
        public CheckAuthResponse() {
        }

        public void onHttpResponse(KsyHttpResponse var1) {
            if(var1.getResponseCode() == 200) {
                try {
                    JSONObject var2 = new JSONObject(var1.getData());
                    AuthInfoManager.this.d = AuthInfoManager.this.new a(var2);
                    AuthInfoManager.this.a();
                } catch (JSONException var7) {
                    AuthInfoManager.this.a();
                } finally {
                    AuthInfoManager.this.i = null;
                }
            } else {
                AuthInfoManager.this.a();
                AuthInfoManager.this.i = null;
            }

        }
    }
}
